package cn.itcast.dao.impl;

import cn.itcast.dao.IUserDao;
import cn.itcast.pojo.User;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserDaoImpl implements IUserDao {

    private SqlSession sqlSession;

    public UserDaoImpl(SqlSession sqlSession) {
        this.sqlSession = sqlSession;
    }

    @Override
    public User queryUserById(Long id) {
        return sqlSession.selectOne("UserDaoMapper.queryUserById",id);
    }

    @Override
    public List<User> queryUserList() {
        return sqlSession.selectList("UserDaoMapper.queryUserList");
    }

    @Override
    public void insertUser(User user) {
        int insert = sqlSession.insert("UserDaoMapper.insertUser", user);
        System.out.println(insert);
        //sqlSession.commit();

    }

    @Override
    public void updateUser(User user) {
        int update = sqlSession.update("UserDaoMapper.updateUser", user);
        System.out.println(update);

    }

    @Override
    public void deleteUserById(Long id) {
        sqlSession.delete("UserDaoMapper.deleteUserById",id);

    }
}
